package com.itheima.mp;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.itheima.mp.mapper.UserMapper;
import com.itheima.mp.pojo.User;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;

import java.util.List;

@SpringBootTest
public class test {

    @Autowired
    private UserMapper userMapper;
    @Test
    public void test(){

        List<User> users = userMapper.selectList(Wrappers.emptyWrapper());
        for (User user : users) {
            System.out.println(user);
        }
    }

    /**
     * 查询测试
     */
    @Test
    public void testMapper(){

        QueryWrapper<User> queryWrapper = new QueryWrapper<>();

        //queryWrapper.or(qw -> queryWrapper.eq("name","张三").eq("password","123"));
        //queryWrapper.or(qw ->queryWrapper.eq("name","张三").ge("age","13"));

        queryWrapper.eq("name","李四").or().eq("age", 24);
        List<User> users = userMapper.selectList(queryWrapper);
        for (User user : users) {
            System.out.println(user);
        }
    }

    /**
     * lambdaQuery测试
     */
    @Test
    public void testLambda(){
        LambdaQueryWrapper<User> queryWrapper = new LambdaQueryWrapper<>();

        queryWrapper.eq(User::getName,"李四");
        List<User> users = userMapper.selectList(queryWrapper);
        for (User user : users) {
            System.out.println(user);
        }
    }

    /**
     * 自动填充测试，自动填充password
     */
    @Test
    public void testInsert(){
        User user = new User();
        user.setName("TOm");
        user.setUserName("tom");
        user.setAge(45);

        int insert = userMapper.insert(user);
    }
}
